﻿using _002_Model;
using IService;
using Microsoft.Extensions.DependencyInjection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace _002_MVVM控制反转_IOC
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //IStudentService? studentService = ((App)(App.Current)).ServiceProvider.GetService<IStudentService>();
        IStudentService? studentService = App.Current.ServiceProvider.GetService<IStudentService>();
        public MainWindow(IStudentService studentService)
        {
            //this.studentService = studentService;
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //StudentService service = new StudentService();
            //service.Add(new Student() { Id = 10 });

            if (studentService != null)
            {
                studentService.Add(new Student() { Id = 10 });
            }
        }
    }
}